package com.moss.cloud.plugins.biz.controller;

import com.moss.cloud.common.core.constant.ServiceList;
import com.moss.cloud.common.core.model.Result;
import com.moss.cloud.common.security.annotation.SysLog;
import com.moss.cloud.plugins.api.model.from.BaseFrom;
import com.moss.cloud.plugins.api.model.from.DataSourceConfFrom;
import com.moss.cloud.plugins.api.model.param.DataSourceConfParam;
import com.moss.cloud.plugins.biz.service.IDataSourceConfService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 数据源配置前端控制器
 *
 * @author 瑾年
 * @date 2024年1月3日
 */
@RestController
@RequestMapping(ServiceList.PLUGINS + "/dataSourceConf")
public class DataSourceConfController {
    private final IDataSourceConfService dataSourceConfService;

    public DataSourceConfController(IDataSourceConfService dataSourceConfService) {
        this.dataSourceConfService = dataSourceConfService;
    }

    /**
     * 新增数据源配置
     *
     * @param dataSourceConfFrom
     * @return
     */
    @PostMapping("/saveDataSourceConf")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "新增数据源配置")
    public Result<?> saveDataSourceConf(@RequestBody @Validated DataSourceConfFrom dataSourceConfFrom){
        return Result.success(dataSourceConfService.saveDataSourceConf(dataSourceConfFrom));
    }

    /**
     * 更新数据源配置
     *
     * @param dataSourceConfFrom
     * @return
     */
    @PostMapping("/updateDataSourceConf")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "更新数据源配置")
    public Result<?> updateDataSourceConf(@RequestBody @Validated DataSourceConfFrom dataSourceConfFrom){
        return Result.success(dataSourceConfService.updateDataSourceConf(dataSourceConfFrom));
    }

    /**
     * 删除数据源配置
     *
     * @param baseFrom
     * @return
     */
    @PostMapping("/removeDataSourceConf")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "删除数据源配置")
    public Result<?> removeDataSourceConf(@RequestBody @Validated BaseFrom baseFrom){
        return Result.success(dataSourceConfService.removeDataSourceConf(baseFrom));
    }

    /**
     * 数据源配置分页查询
     *
     * @param dataSourceConfParam
     * @return
     */
    @PostMapping("/page")
    @SysLog(serverName = ServiceList.MOSS_CLOUD_PLUGINS, operation = "数据源配置分页查询")
    public Result<?> page(@RequestBody @Validated DataSourceConfParam dataSourceConfParam){
        return Result.success(dataSourceConfService.page(dataSourceConfParam));
    }

}
